<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Billing extends MY_Controller {
    
    public function __construct()
    {
        parent::__construct(); 
        $this->load->model('billing_mod');
    }
    
	/**
     *   
     *    
     */
    public function index( )
    {        
        $data['menu_page'] = "billing"; // Koja je stranica. current menu item
        $data['billings']=NULL;
        $data['statuses']=$this->billing_mod->getBillingStatuses();
        $data['total']=  $this->billing_mod->getTotal("day");
        // Definisi koji se view ucitava
        $data['contents'] = 'billing/billing_home';
        
        $this->load->view('main',$data);
    }
    public function filter_submit() {
        try {
            $filter = $this->input->post('filter');
            $data['billings'] = $this->billing_mod->getBillings($filter);
            $num_users = count($data['billings']);
            $html = $this->load->view('billing/billing_list', $data, true);
            $response = array(
                'ind' => 1,
                'msg' => "",
                'num_users' => $num_users,
                'html' => $html
            );
        } catch (Exception $e) {

            $response = array(
                'ind' => 0,
                'msg' => 'Following errors occured: <br />' . $e->getMessage(),
                'num_users' => 0,
                'html' => ''
            );
        }
        echo json_encode($response);
    }
    public function change_billing_period(){
        
        try {
            $period=$this->input->post('period');
            $amount = $this->billing_mod->getTotal($period);
       $response = array(
                'ind' => 1,
                'msg' => "",
                'amount' => $amount->amount
            );
        } catch (Exception $e) {

            $response = array(
                'ind' => 0,
                'msg' => 'Following errors occured: <br />' . $e->getMessage(),
                'amount' => ''
            );
        }
        echo json_encode($response);
    }
   
}
/* End of file billing.php */
/* Location: ./application/controllers/billing.php */